<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category SwooleCommand.php
 * @Depiction
 * @Author hwy <429208948@qq.com>
 * @Date 2022/3/4  16:55
 * +--------------------------------------------------------+
 */

namespace App\Console\Commands;


use App\Services\Swoole\WebSwoole;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class SwooleCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'swoole {action} {type}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '开启 swoole 服务';

    private $swoole;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $arg  = $this->argument('action');
        $type = $this->argument('type') ?? 'web_swoole';

        $this->info($type . ' observer started');

        switch ($type) {
            case 'web_swoole':
                $this->swoole = new WebSwoole();
                break;
            case 'tcp':
                $this->error("unknown type");
                break;
            default:
                $this->error("unknown type");
                return false;
        }


        switch ($arg) {
            case 'start':
                $this->swoole->start();
                break;
            case 'stop':
                break;
            case 'restart':
                $this->swoole->reload();
                break;
            default:
                $this->error("unknown command");
        }
    }

}
